package com.transactional.service.differentclass;

import com.transactional.bean.User;
import com.transactional.dao.UserDao;
import com.transactional.service.innerclass.InnerService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Deacription TODO
 * @Author baohuajie
 * @Date 2021/5/12 9:22
 * @Version 1.0
 **/
@Service
public class Service2 {

    @Autowired
    private UserDao userDao;


//    @Transactional
    public int Service2Insert(User user){
        int i = userDao.insert(user);
        return i;
    }

    public int demo1(User user) {
        user.setUserName(user.getUserName() + "Service2.demo1");
        int i = userDao.insert(user);
        try {
            int a = 1/0;
        } catch (Exception e) {
            throw new RuntimeException();
        }
        return i;
    }

    @Transactional
    public int multithreadDemo2(User user) {
        user.setUserName(user.getUserName() + "Service2.multithreadDemo2");
        int i = userDao.insert(user);
        try {
            int a = 1/0;
        } catch (Exception e) {
            throw new RuntimeException();
        }
        return i;
    }

    @Transactional
    public int afterCommitDemo1(User user) {
        user.setUserName(user.getUserName() + "Service2.afterCommitDemo1");
        int i = userDao.insert(user);
        try {
            int a = 1/0;
        } catch (Exception e) {
            throw new RuntimeException();
        }
        return i;
    }

}
